package org.xtense.rcp;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
	private IWorkbenchAction quitAction;
	private IWorkbenchAction aboutAction;
	private IAction xtensePersAction;
	
	private IWorkbenchAction preferencesAction;
	
    public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
        super(configurer);
    }

    protected void makeActions(IWorkbenchWindow window) {
    	
    	quitAction = ActionFactory.QUIT.create(window);
    	xtensePersAction = new XtensePersAction();
    	aboutAction = ActionFactory.ABOUT.create(window);
    	preferencesAction = ActionFactory.PREFERENCES.create(window);
    	register(quitAction);
    	register(aboutAction);
    	register(preferencesAction);
    }

    protected void fillMenuBar(IMenuManager menuBar) {
    	IMenuManager fileMenu = new MenuManager("&File",IWorkbenchActionConstants.M_FILE);
    	IMenuManager persMenu = new MenuManager("&Perspective");
    	IMenuManager helpMenu = new MenuManager("&Help",IWorkbenchActionConstants.M_HELP);
    	menuBar.add(fileMenu);
    	menuBar.add(persMenu);
    	menuBar.add(helpMenu);
    	
    	fileMenu.add(preferencesAction);
    	fileMenu.add(new Separator());
    	fileMenu.add(quitAction);
    	persMenu.add(xtensePersAction);
    	helpMenu.add(aboutAction);
    }
    
    private class XtensePersAction extends Action {
    	public XtensePersAction() {
    		setId("Action_Xtense_Perspective");
    		setText("Xtense");
    	}
    	
    	public void run(){
    		Activator.showPerspective("XtenseRCP.perspective");
    	}
    }
    
}
